// pages/profile/index.ts
Page({
  /**
   * 页面的初始数据
   */
  onShow() {
    this.getUserInfo()
  },

  data: {
    avatar: '',
    nickName: '',
  },
  async setUserInfo(e) {
    await wx.http.put('/userInfo', {
      nickName: e.detail.value,
    })
  },
  async changeAvatar(e) {
    const res = await wx.http.upload('/upload', {
      name: 'file',
      filePath: e.detail.avatarUrl,
      formData: {
        type: 'avatar',
      },
    })
    this.setData({
      avatar: res.data.url,
    })
  },
  async getUserInfo() {
    const res = await wx.http.get('/userInfo')
    this.setData({
      nickName: res.data.nickName,
      avatar: res.data.avatar,
    })
  },
})
